package com.fsxgt.datagrid.ds.tool;

import org.apache.commons.lang3.StringUtils;


public abstract class BaseSqlTool implements MetaSqlInterface {

	@Override
    public String getSQLQueryFieldsBySql(String sqlText) {
        return "SELECT * FROM (" + sqlText + ") a where 1=0";
    }
    @Override
    public String getSQLQueryFieldsByTableName(String schema,String tableName) {
    	
    	if(StringUtils.isNotEmpty(schema)&&tableName.indexOf(".")==-1) {
    		tableName=schema+"."+tableName;
    	}
        return "SELECT * FROM " + tableName + " where 1=0";
    }

    @Override
    public String getSQLQueryTablesNameComments() {
        return "select table_name,table_comment from information_schema.tables where table_schema=?";
    }

    @Override
    public String getSQLQueryTableNameComment() {
        return "select table_name,table_comment from information_schema.tables where table_schema=? and table_name = ?";
    }

    @Override
    public String getSQLQueryPrimaryKey() {
        return null;
    }

    @Override
    public String getSQLQueryComment(String schemaName, String tableName, String columnName) {
        return null;
    }

    @Override
    public String getSQLQueryColumns(String... args) {
        return null;
    }

    @Override
    public String getMaxId(String tableName, String primaryKey) {
        return String.format("select max(%s) from %s",primaryKey,tableName);
    }
    
    @Override
    public String getColumnValue(String tableName, String column) {
        return String.format("select %s from %s",column,tableName);
    }
    
    

    @Override
    public String getSQLQueryTableSchema(String... args) {
        return null;
    }
    
    

    @Override
    public String getSQLQueryTables() {
        return null;
    }

    @Override
    public String getSQLQueryTables(String... tableSchema) {
        return null;
    }
    public String getTestSql() {
    	
		return "select 1";
    	
    }
    
}
